package com.yc.snack.controller;

import com.yc.snack.biz.IAdminInfoBiz;
import com.yc.snack.biz.impl.AdminInfoBizImpl;
import com.yc.snack.entity.AdminInfo;
import com.yc.snack.util.ConstantInfo;
import com.yc.snack.util.RequestParamUtil;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**控制层
 * @Auther: HuYang
 * @Date: 2022/11/6 - 11 - 06 - 16:56
 * @Description: com.yc.snack.controller
 * @version: 1.0
 */
@WebServlet("/admin/*")
public class AdminInfoController extends BaseController {
    /**
     * 登录方法
     * @param request
     * @param response
     */
    protected  void login(HttpServletRequest request, HttpServletResponse response) throws IOException {
        //获取参数
        AdminInfo af = RequestParamUtil.getParams(AdminInfo.class,request);
        System.out.println(af);

        //调用业务模型层处理
        IAdminInfoBiz adminInfoBiz = new AdminInfoBizImpl();
        AdminInfo admin = adminInfoBiz.login(af);
        //返回结果
        if (admin == null ){
            this.send(response,500,"账号或密码错误!");
            return;
        }

        request.getSession().setAttribute(ConstantInfo.CURRENTLOGINADMIN,admin);
        this.send(response,200,"成功");
        return;
    }
}
